<h2 id="事件"> 事件</h2>
<p>你可以根据需要事先定义好一些回调函数，uTools会在事件产生时主动调用它们。</p>
<h3 id="onPluginReady(callback)">
    <code>onPluginReady(callback)</code></h3>
<blockquote>
    <p>当插件装载成功，uTools将会主动调用这个方法（生命周期内仅调用一次）。</p>
    <p>注意：在此方法未被执行前，无法调用其他方法。</p>
</blockquote>
<h4 id="实例"> 实例</h4>
<div class="language-js extra-class">
    <pre class="language-js"><code>utools<span class="token punctuation">.</span><span class="token function">onPluginReady</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'插件初始化完成'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</div>
<ul>
    <li><code>callback</code> Function</li>
</ul>
<h3 id="onPluginEnter(callback)">
    <code>onPluginEnter(callback)</code></h3>
<blockquote>
    <p>每当插件从后台进入到前台时，uTools将会主动调用这个方法。</p>
</blockquote>
<h4 id="实例-2"> 实例</h4>
<div class="language-js extra-class">
    <pre class="language-js"><code>utools<span class="token punctuation">.</span><span class="token function">onPluginEnter</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">{</span>code<span class="token punctuation">,</span> type<span class="token punctuation">,</span> payload<span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'用户进入插件'</span><span class="token punctuation">,</span> code<span class="token punctuation">,</span> type<span class="token punctuation">,</span> payload<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</div>
<ul>
    <li><code>callback</code> Function
        <ul>
            <li><code>Object</code>
                <ul>
                    <li><code>code</code> String</li>
                    <li><code>type</code> String</li>
                    <li><code>payload</code> String/Object/Array</li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
<h3 id="onPluginOut(callback)">
    <code>onPluginOut(callback)</code></h3>
<blockquote>
    <p>每当插件从前台进入到后台时，uTools将会主动调用这个方法。</p>
</blockquote>
<h4 id="实例-3"> 实例</h4>
<div class="language-js extra-class">
    <pre class="language-js"><code>utools<span class="token punctuation">.</span><span class="token function">onPluginOut</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'用户退出插件'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</div>
<ul>
    <li><code>callback</code> Function</li>
</ul>
<h3 id="onPluginDetach(callback)">
    <code>onPluginDetach(callback)</code></h3>
<blockquote>
    <p>用户对插件进行分离操作时，uTools将会主动调用这个方法。</p>
</blockquote>
<h4 id="实例-4"> 实例</h4>
<div class="language-js extra-class">
    <pre class="language-js"><code>utools<span class="token punctuation">.</span><span class="token function">onPluginDetach</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'插件被分离'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</div>
<ul>
    <li><code>callback</code> Function</li>
</ul>
<h3 id="onDbPull(callback)">
    <code>onDbPull(callback)</code></h3>
<blockquote>
    <p>当此插件的数据在其他设备上被更改后同步到此设备时，uTools将会主动调用这个方法（必须在插件可视的情况下才会触发）</p>
</blockquote>
<h4 id="实例-5"> 实例</h4>
<div class="language-js extra-class">
    <pre class="language-js"><code>utools<span class="token punctuation">.</span><span class="token function">onDbPull</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'onDbPull'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
</div>
<ul>
    <li><code>callback</code> Function</li>
</ul>